const getUrlData = require('./getUrlData');
const getRequestJsonData = require('./getRequestJsonData');

// 获取用户列表
let getUserList = async type => {
  let getUserJson = getRequestJsonData.getUserList(type);
  let res = await getUrlData.getUrlData(
    'http://laiyipanhall.henanyaoneng.cn:8001',
    'get_qipaiguan_agentroomallgameuserinfo',
    getUserJson
  );
  let userList = res.data;
  if (userList.querycount <= 0) return null;
  // 用户数据存储
  let formatUserList = userList.data.filter(item => Object.assign(item, { formatUserName: '' }));
  return formatUserList;
};

// 获取赛事统计列表
let getGameList = async (type, time) => {
  if (!time) return new Error('没填写时间哦');
  let getGameJson = getRequestJsonData.getGameList(type, time);
  let res = await getUrlData.getUrlData(
    'http://laiyipanhall.henanyaoneng.cn:8001',
    'get_dalianmeng_agentroomsetletinfo',
    getGameJson
  );
  let gameList = res.data || [];
  if (gameList.querycount <= 0) return [];
  return gameList.data;
};

// 获取用户详细信息
let getUserDetailInfo = async (userid) => {
  if (!userid) return new Error('没填写userid哦');
  let getGameJson = getRequestJsonData.getUserDetailInfo(userid);
  let res = await getUrlData.getUrlData('http://laiyipanhall.henanyaoneng.cn:8000', 'base_info', getGameJson);
  let userinfo = res.data;
  if (!userinfo.name) return null;
  return userinfo;
};

module.exports = {
  getUserList,
  getGameList,
  getUserDetailInfo
};
